package cc.mrbird.plan.service.impl;

import cc.mrbird.common.service.impl.BaseService;
import cc.mrbird.plan.dao.TrainingMapper;
import cc.mrbird.plan.domain.Training;
import cc.mrbird.plan.service.TrainingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service("trainingService")
public class TrainingServiceImpl extends BaseService<Training> implements TrainingService {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private TrainingMapper trainingMapper;
    /*@Override
    public List<Training> findTrainings(Training training, QueryRequest request) {
        try {
            return this.trainingMapper.findTrainingList(training);
        } catch (Exception e) {
            log.error("error", e);
            return new ArrayList<>();
        }
    }*/

  /*  @Override
    public Training findByName(String contact_name) {
        Example example = new Example(User.class);
        example.createCriteria().andCondition("lower(contact_name)=", contact_name.toLowerCase());
        List<Training> list = this.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }*/

    @Override
    public void add(Training training) {
        this.save(training);
    }

    @Override
    public void update(Training training) {
        this.updateNotNull(training);
    }

    @Override
    public Training findById(Integer id) {
        try {
            return this.trainingMapper.findById(id);
        } catch (Exception e) {
            log.error("error", e);
            return new Training();
        }
    }

    @Override
    @Transactional
    public void delete(String ids) {
        List<String> list = Arrays.asList(ids.split(","));
        this.batchDelete(list, "unit_id", Training.class);
    }
}
